package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;
import com.yuwj.chinaa.entity.EntityMyCommunity;
import com.yuwj.chinaa.presenter.IPresenter;
import com.yuwj.chinaa.presenter.presenterImpl.PresenterImpl;
import com.yuwj.chinaa.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyCommunityActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_today_share_num)
    TextView tvTodayShareNum;
    @BindView(R.id.tv_total_share_num)
    TextView tvTotalShareNum;
    @BindView(R.id.tv_inv_count)
    TextView tvInvCount;
    @BindView(R.id.tv_inv_count_no1)
    TextView tvInvCountNo1;
    @BindView(R.id.tv_inv_count_no2)
    TextView tvInvCountNo2;

    EntityMyCommunity entityMyCommunity;
    IPresenter presenter;

    public static Intent createIntent(Context context) {
        return new Intent(context, MyCommunityActivity.class);
    }

    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_my_comunity;
    }

    @Override
    public void initParam() {
        presenter = new PresenterImpl(this);
    }

    @Override
    public void initView() {
        tvTitle.setText("我的社区");
    }

    public void updateView() {
        tvTodayShareNum.setText(entityMyCommunity.getShareNumberToday() + "");
        tvTotalShareNum.setText(entityMyCommunity.getShareNumber() + "");
        tvInvCount.setText(entityMyCommunity.getInvCount() + "");
        tvInvCountNo1.setText(entityMyCommunity.getInvCountNo1() + "人");
        tvInvCountNo2.setText(entityMyCommunity.getInvCountNo2() + "人");

    }

    @Override
    public void initOperator() {
        presenter.getUserCommunity("");
    }

    @Override
    public void onGetUserCommunitySuccess(EntityMyCommunity entityMyCommunity) {
        super.onGetUserCommunitySuccess(entityMyCommunity);
        this.entityMyCommunity = entityMyCommunity;
        updateView();
    }

    @Override
    public void onGetUserCommunityFail(Exception e) {
        super.onGetUserCommunityFail(e);
        ToastUtil.getInstance().shortLength(context, e.getMessage());
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
        }
    }
}
